﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class frmDanhSachPhong : System.Web.UI.Page
{
    DataClassesDataContext db = new DataClassesDataContext();
    protected void Page_Load(object sender, EventArgs e)
    {
        Int32 btID = 0, pnID = 0;

        var khuvuc = (from k in db.KHU_VUCs orderby k.KV_ID ascending select k ).ToList ();
        
        for (int j = 0; j < khuvuc .Count ; j++)
			{
			    Panel pn = new Panel();
                pn.ID = "panel" + pnID.ToString();
                pn.BorderStyle = BorderStyle.Double; 
                place.Controls.Add(pn);
                pnID = pnID + 1;
                //Response.Write("<fieldset>");
                //Response.Write(" <legend >" + khuvuc[j].KV_TEN + " </legend>");


                Label lb = new Label();
                lb.Text = "<div align=\"center\" class=\"thediv\" >" + khuvuc[j].KV_TEN + "</div>";
                lb.CssClass = "LabelHienThiDanhSach";
                pn.Controls.Add(lb);
              //hien thi danh sach phong theo khu vuc
                     var phong = (from p in db.PHONGs where p.KHU_VUC .KV_ID == khuvuc [j].KV_ID select p).ToList ();
       
                for (int i = 0; i < phong.Count ; i++)
                {


                    Button btn = new Button();

                    btn.ID = "Phòng " + phong[i].P_MA; ;
                    btn.Text = "Phòng " + phong[i].P_MA;
                    //btn.Width = 60;
                    //btn.Height = 70;
                    btn.Font.Size = 8;


                    btn.BackColor = System.Drawing.Color.FromArgb(int.Parse(phong[i].TRANG_THAI_PHONG.TT_MAU));
                    //btn.ImageUrl = "images/gnome_go_home.png";
                    
                    btn.CssClass = "button";

                    btn.Click += new EventHandler(btn_Click);
                    //btn.Click += new ImageClickEventHandler(btn_Click);
                    btID = btID + 1;

                   

                    pn.Controls.Add(btn);
                }
            //Response.Write("</fieldset>");
            
			}



        var mau = (from tt in db.TRANG_THAI_PHONGs select tt).ToList();
        for (int k = 0; k < mau.Count ; k++)
        {
                    Button btn = new Button();
                    btn.ID = "Màu " + mau[k].TT_ID; ;
                    btn.Text = mau[k].TT_PHONG;
                    btn.Width = 80;
                    btn.Height = 30;
                    btn.CssClass = "button";
                    btn.BackColor = System.Drawing.Color.FromArgb(int.Parse(mau[k].TT_MAU));
                    ghichu.Controls.Add(btn);

        }
     
      
    }

    void btn_Click(object sender, EventArgs e)
    {
        lit.Text = string.Format("Button {0} was pressed.", ((Button)sender).ID);
    }
    
}
